from applications.extensions import ma
from marshmallow import fields
from applications.models import User


# 沃尔玛用户表的序列化类
class WalmartUserOutSchema(ma.Schema):
    id = fields.Integer()
    name = fields.Str()
    phone = fields.Str()
    realName = fields.Method("get_realName")
    create_at = fields.DateTime()

    def get_realName(self, obj):
        if obj.create_id != None:
            return User.query.filter_by(id=obj.create_id).first().realname
        else:
            return None
